parallel-debian: Support being run as non-root
authorColin Walters <walters@verbum.org>
Thu, 10 Nov 2011 16:52:48 +0000 (11:52 -0500)
committerColin Walters <walters@verbum.org>
Thu, 10 Nov 2011 16:52:48 +0000 (11:52 -0500)
parallel-debian/.gitignore
parallel-debian/Makefile
parallel-debian/chroot_break.c [deleted file]
parallel-debian/debian-setup.sh
parallel-debian/gnomeos-make-base.sh [new file with mode: 0755]
parallel-debian/gnomeos-make-image.sh [deleted file]

index 95bdbbededd1ea230ba763d592b54386991408ed..d42173ae069968ea95c62916276ccc5ecccb9f5d 100644 (file)
@@ -1,2 +1 @@
-chroot_break
 ostree_switch_root
index 97ec6c002f7228a7cbcb13aaedf265fc09ed1651..a00e61102c86386479f3e865ca2f53d866818951 100644 (file)
@@ -1,8 +1,4 @@
-
-all: ostree_switch_root chroot_break
+all: ostree_switch_root
 
 ostree_switch_root: ostree_switch_root.c Makefile
        gcc -Wall -o $@ $<
-
-chroot_break: chroot_break.c Makefile
-       gcc -Wall -o $@ $<
diff --git a/parallel-debian/chroot_break.c b/parallel-debian/chroot_break.c
deleted file mode 100644 (file)
index 2a34716..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- *
- * chroot_break: Exit out of active chroot(2) if any.  Requires root privileges.
- *
- * Copyright (C) 2011 Colin Walters <walters@verbum.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-int
-usage (const char *self,
-       int         ecode)
-{
-  fprintf (stderr, "usage: %s PROGRAM [ARGS...]\n", self);
-
-  return ecode;
-}
-
-int
-main (int  argc,
-      char **argv)
-{
-  const char *template = "/tmp/chroot.XXXXXX";
-  char *tmpdir;
-  DIR *tmp;
-  struct stat current;
-  struct stat up;
-
-  if (argc < 2)
-    return usage (argv[0], 1);
-
-  tmpdir = strdup (template);
-  if (!mkdtemp (tmpdir))
-    {
-      perror ("mkdtemp");
-      return 1;
-    }
-
-  tmp = opendir ("/tmp");
-  if (!tmp)
-    {
-      perror ("opening /tmp");
-      return 1;
-    }
-
-  if (chroot (tmpdir) < 0)
-    {
-      perror ("chroot into tempdir");
-      return 1;
-    }
-
-  do 
-    {
-      if (stat (".", &current) < 0)
-       {
-         perror ("stat");
-         return 1;
-       }
-      if (stat ("..", &up) < 0)
-       {
-         perror ("stat");
-         return 1;
-       }
-      if (current.st_dev == up.st_dev
-         && current.st_ino == up.st_ino)
-       break;
-      if (chdir ("..") < 0)
-       {
-         perror ("chdir");
-         return 1;
-       }
-    } while (1);
-
-  if (chroot (".") < 0)
-    {
-      perror ("chroot into real root");
-      return 1;
-    }
-
-  if (unlinkat (dirfd (tmp), strrchr (tmpdir, '/') + 1, AT_REMOVEDIR) < 0)
-    {
-      perror ("cleaning up tmpdir");
-      return 1;
-    }
-
-  closedir (tmp);
-
-  if (execv (argv[1], &argv[1]) < 0)
-    {
-      perror ("Running child process");
-      return 1;
-    }
-  /* Should not be reached */
-  return 1;
-}
index c5aabb73265e52a4b83d9cf280f891dde5c80f56..732a3837ca44fc1bdde1e61e689a16f8515be383 100755 (executable)
@@ -5,31 +5,31 @@
 set -e
 set -x
 
-echo gnomeos > /etc/hostname
+echo gnomeos >./etc/hostname
 
-cat > /etc/default/locale <<EOF
+cat >./etc/default/locale <<EOF
 LANG="en_US.UTF-8"
 EOF
 
-cp -p /usr/share/sysvinit/inittab /etc/inittab
-cp -p /usr/share/base-files/nsswitch.conf /etc/nsswitch.conf
+cp -p ./usr/share/sysvinit/inittab ./etc/inittab
+cp -p ./usr/share/base-files/nsswitch.conf ./etc/nsswitch.conf
 
-cat >/etc/pam.d/common-account <<EOF
+cat >./etc/pam.d/common-account <<EOF
 account [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so 
 account requisite                       pam_deny.so
 account required                        pam_permit.so
 EOF
-cat >/etc/pam.d/common-auth <<EOF
+cat >./etc/pam.d/common-auth <<EOF
 auth    [success=1 default=ignore]      pam_unix.so nullok_secure
 auth    requisite                       pam_deny.so
 auth    required                        pam_permit.so
 EOF
-cat >/etc/pam.d/common-password <<EOF
+cat >./etc/pam.d/common-password <<EOF
 password        [success=1 default=ignore]      pam_unix.so obscure sha512
 password        requisite                       pam_deny.so
 password        required                        pam_permit.so
 EOF
-cat >/etc/pam.d/common-session <<EOF
+cat >./etc/pam.d/common-session <<EOF
 session [default=1]                     pam_permit.so
 session requisite                       pam_deny.so
 session required                        pam_permit.so
@@ -37,14 +37,8 @@ session required        pam_unix.so
 EOF
 
 # base-passwd
-cp -p /usr/share/base-passwd/passwd.master /etc/passwd
-cp -p /usr/share/base-passwd/group.master /etc/group
-
-# From debian-installer user-setup
-shadowconfig on
-chpasswd <<EOF
-root:root
-EOF
+cp -p ./usr/share/base-passwd/passwd.master ./etc/passwd
+cp -p ./usr/share/base-passwd/group.master ./etc/group
 
 # Service rc.d defaults
 setuprc () {
@@ -56,8 +50,7 @@ setuprc () {
     shift
     
     for x in $@; do
-       cd /etc/rc${x}.d
-       ln -s ../init.d/$name ${type}${priority}${name}
+       ln -s ../init.d/$name ./etc/rc${x}.d/${type}${priority}${name}
     done
 }
     
diff --git a/parallel-debian/gnomeos-make-base.sh b/parallel-debian/gnomeos-make-base.sh
new file mode 100755 (executable)
index 0000000..eb80b04
--- /dev/null
@@ -0,0 +1,197 @@
+#!/bin/sh
+# -*- indent-tabs-mode: nil; -*-
+# Generate a root filesystem image
+#
+# Copyright (C) 2011 Colin Walters <walters@verbum.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set -e
+set -x
+
+SRCDIR=`dirname $0`
+WORKDIR=`pwd`
+
+DEPENDS="debootstrap"
+
+for x in $DEPENDS; do
+    if ! command -v $x; then
+        cat <<EOF
+Couldn't find required dependency $x
+EOF
+        exit 1
+    fi
+done
+
+if test -z "${OSTREE}"; then
+    OSTREE=`command -v ostree || true`
+fi
+if test -z "${OSTREE}"; then
+    cat <<EOF
+ERROR:
+Couldn't find ostree; you can set the OSTREE environment variable to point to it
+e.g.: OSTREE=~user/checkout/ostree/ostree $0
+EOF
+    exit 1
+fi
+
+if test -z "$DRACUT"; then
+    if ! test -d dracut; then
+        cat <<EOF
+Checking out and patching dracut...
+EOF
+        git clone git://git.kernel.org/pub/scm/boot/dracut/dracut.git
+        (cd dracut; git am $SRCDIR/0001-Support-OSTree.patch)
+        (cd dracut; make)
+    fi
+    DRACUT=`pwd`/dracut/dracut
+fi
+
+case `uname -p` in
+    x86_64)
+        ARCH=amd64
+        ;;
+    *)
+        echo "Unsupported architecture"
+        ;;
+esac;
+
+DEBTARGET=wheezy
+
+INITRD_MOVE_MOUNTS="dev proc sys"
+TOPROOT_BIND_MOUNTS="boot home root tmp"
+OSTREE_BIND_MOUNTS="var"
+MOVE_MOUNTS="selinux mnt media"
+READONLY_BIND_MOUNTS="bin etc lib lib32 lib64 sbin usr"
+
+cd ${WORKDIR}
+OBJ=debootstrap-$DEBTARGET
+if ! test -d ${OBJ} ; then
+    echo "Creating $DEBTARGET.img"
+    mkdir -p ${OBJ}.tmp
+    debootstrap --download-only --arch $ARCH $DEBTARGET ${OBJ}.tmp
+    mv ${OBJ}.tmp ${OBJ}
+fi
+
+cd ${WORKDIR}
+OBJ=$DEBTARGET-fs
+if ! test -d ${OBJ}; then
+    rm -rf ${OBJ}.tmp
+    mkdir ${OBJ}.tmp
+
+    cd ${OBJ}.tmp;
+    mkdir -m 0755 $INITRD_MOVE_MOUNTS $TOPROOT_BIND_MOUNTS
+    chmod a=rwxt tmp
+
+    mkdir ostree
+
+    mkdir -p -m 0755 ostree/var/{log,run}
+
+    mkdir ostree/repo
+
+    $OSTREE --repo=ostree/repo init 
+    
+    BRANCHES=""
+
+    mkdir ostree/worktree
+    cd ostree/worktree
+    mkdir -m 0755 $INITRD_MOVE_MOUNTS $TOPROOT_BIND_MOUNTS $OSTREE_BIND_MOUNTS $READONLY_BIND_MOUNTS $MOVE_MOUNTS sysroot
+    chmod a=rwxt tmp
+    $OSTREE --repo=../repo commit -b gnomeos-filesystem -s "Base filesystem layout"
+    BRANCHES="$BRANCHES gnomeos-filesystem"
+    cd ..
+    rm -rf worktree
+
+    for d in ${WORKDIR}/debootstrap-$DEBTARGET/var/cache/apt/archives/*.deb; do
+        bn=$(basename $d)
+        debname=$(echo $bn | cut -f 1 -d _)
+        debversion=$(echo $bn | cut -f 2 -d _)
+        archivename="archive-${debname}"
+        rm -rf worktree; mkdir worktree;
+        cd worktree;
+        mkdir data;
+        ar x $d;
+        tar -x -z -C data -f data.tar.gz;
+        cd data;
+        $OSTREE --repo=../../repo commit -b "${archivename}" -s "Version ${debversion}"
+        BRANCHES="$BRANCHES $archivename"
+        cd ../..
+    done
+    rm -rf worktree
+
+    $OSTREE --repo=repo compose --out-metadata=./compose-meta worktree $BRANCHES
+    cd worktree
+    $OSTREE --repo=../repo commit --metadata-variant=../compose-meta -b gnomeos -s "Compose of Debian $DEBTARGET"
+    cd ..
+    rm -rf worktree
+    
+    cd ${WORKDIR}
+    if test -d ${OBJ}; then
+        mv ${OBJ} ${OBJ}.old
+    fi
+    mv ${OBJ}.tmp ${OBJ}
+    rm -rf ${OBJ}.old
+fi
+
+# TODO download source for above
+# TODO download build dependencies for above
+
+cd ${WORKDIR}
+OBJ=gnomeos-fs
+if ! test -d ${OBJ}; then
+    rm -rf ${OBJ}.tmp
+    cp -al $DEBTARGET-fs ${OBJ}.tmp
+    cd ${OBJ}.tmp/ostree;
+    rm -rf worktree
+    $OSTREE --repo=repo checkout gnomeos worktree
+    cd worktree
+    ${SRCDIR}/debian-setup.sh
+    $OSTREE --repo=../repo commit -b gnomeos -s "Run debian-setup.sh"
+    cd ..
+    rm -rf worktree
+
+    rev=$($OSTREE --repo=repo rev-parse gnomeos);
+    $OSTREE --repo=repo checkout ${rev} gnomeos-${rev}
+    $OSTREE --repo=repo run-triggers gnomeos-${rev}
+    ln -s gnomeos-${rev} current
+    
+    cd ${WORKDIR}
+    if test -d ${OBJ}; then
+        mv ${OBJ} ${OBJ}.old
+    fi
+    mv ${OBJ}.tmp ${OBJ}
+    rm -rf ${OBJ}.old
+fi
+
+cd ${WORKDIR}
+cp ${SRCDIR}/ostree_switch_root ${WORKDIR}
+
+kv=`uname -r`
+kernel=/boot/vmlinuz-${kv}
+if ! test -f "${kernel}"; then
+    cat <<EOF
+Failed to find ${kernel}
+EOF
+fi
+
+cd ${WORKDIR}
+OBJ=gnomeos-initrd.img
+VOBJ=gnomeos-initrd-${kv}.img
+if ! test -f ${OBJ}; then
+    rm -f ${OBJ}.tmp ${VOBJ}.tmp
+    $DRACUT -l -v -o plymouth --include `pwd`/ostree_switch_root /sbin/ostree_switch_root ${VOBJ}.tmp
+    mv ${VOBJ}.tmp ${VOBJ}
+    ln -sf ${VOBJ} gnomeos-initrd.img
+fi
diff --git a/parallel-debian/gnomeos-make-image.sh b/parallel-debian/gnomeos-make-image.sh
deleted file mode 100755 (executable)
index 8f10705..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-#!/bin/sh
-# -*- indent-tabs-mode: nil; -*-
-# Generate a root filesystem image
-#
-# Copyright (C) 2011 Colin Walters <walters@verbum.org>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-set -e
-set -x
-
-SRCDIR=`dirname $0`
-WORKDIR=`pwd`
-
-DEPENDS="debootstrap qemu-img grubby"
-
-for x in $DEPENDS; do
-    if ! command -v $x; then
-        cat <<EOF
-Couldn't find required dependency $x
-EOF
-        exit 1
-    fi
-done
-
-if test $(id -u) != 0; then
-    cat <<EOF
-This script must be run as root.
-EOF
-    exit 1
-fi
-
-if test -z "${OSTREE}"; then
-    OSTREE=`command -v ostree || true`
-fi
-if test -z "${OSTREE}"; then
-    cat <<EOF
-ERROR:
-Couldn't find ostree; you can set the OSTREE environment variable to point to it
-e.g.: OSTREE=~user/checkout/ostree/ostree $0
-EOF
-    exit 1
-fi
-
-if test -z "$DRACUT"; then
-    if ! test -d dracut; then
-        cat <<EOF
-Checking out and patching dracut...
-EOF
-        git clone git://git.kernel.org/pub/scm/boot/dracut/dracut.git
-        (cd dracut; git am $SRCDIR/0001-Support-OSTree.patch)
-        (cd dracut; make)
-    fi
-    DRACUT=`pwd`/dracut/dracut
-fi
-
-case `uname -p` in
-    x86_64)
-        ARCH=amd64
-        ;;
-    *)
-        echo "Unsupported architecture"
-        ;;
-esac;
-
-DEBTARGET=wheezy
-
-INITRD_MOVE_MOUNTS="dev proc sys"
-TOPROOT_BIND_MOUNTS="boot home root tmp"
-OSTREE_BIND_MOUNTS="var"
-MOVE_MOUNTS="selinux mnt media"
-READONLY_BIND_MOUNTS="bin etc lib lib32 lib64 sbin usr"
-
-cd ${WORKDIR}
-OBJ=debootstrap-$DEBTARGET
-if ! test -d ${OBJ} ; then
-    echo "Creating $DEBTARGET.img"
-    mkdir -p ${OBJ}.tmp
-    debootstrap --download-only --arch $ARCH $DEBTARGET ${OBJ}.tmp
-    mv ${OBJ}.tmp ${OBJ}
-fi
-
-cd ${WORKDIR}
-OBJ=$DEBTARGET-fs
-if ! test -d ${OBJ}; then
-    rm -rf ${OBJ}.tmp
-    mkdir ${OBJ}.tmp
-
-    cd ${OBJ}.tmp;
-    mkdir -m 0755 $INITRD_MOVE_MOUNTS $TOPROOT_BIND_MOUNTS
-    chmod a=rwxt tmp
-
-    mkdir ostree
-
-    mkdir -p -m 0755 ostree/var/{log,run}
-
-    mkdir ostree/repo
-
-    $OSTREE --repo=ostree/repo init 
-    
-    BRANCHES=""
-
-    mkdir ostree/worktree
-    cd ostree/worktree
-    mkdir -m 0755 $INITRD_MOVE_MOUNTS $TOPROOT_BIND_MOUNTS $OSTREE_BIND_MOUNTS $READONLY_BIND_MOUNTS $MOVE_MOUNTS sysroot
-    chmod a=rwxt tmp
-    $OSTREE --repo=../repo commit -b gnomeos-filesystem -s "Base filesystem layout"
-    BRANCHES="$BRANCHES gnomeos-filesystem"
-    cd ..
-    rm -rf worktree
-
-    for d in ${WORKDIR}/debootstrap-$DEBTARGET/var/cache/apt/archives/*.deb; do
-        bn=$(basename $d)
-        debname=$(echo $bn | cut -f 1 -d _)
-        debversion=$(echo $bn | cut -f 2 -d _)
-        archivename="archive-${debname}"
-        rm -rf worktree; mkdir worktree;
-        cd worktree;
-        mkdir data;
-        ar x $d;
-        tar -x -z -C data -f data.tar.gz;
-        cd data;
-        $OSTREE --repo=../../repo commit -b "${archivename}" -s "Version ${debversion}"
-        BRANCHES="$BRANCHES $archivename"
-        cd ../..
-    done
-    rm -rf worktree
-
-    $OSTREE --repo=repo compose --out-metadata=./compose-meta worktree $BRANCHES
-    cd worktree
-    $OSTREE --repo=../repo commit --metadata-variant=../compose-meta -b gnomeos -s "Compose of Debian $DEBTARGET"
-    cd ..
-    rm -rf worktree
-    
-    cd ${WORKDIR}
-    if test -d ${OBJ}; then
-        mv ${OBJ} ${OBJ}.old
-    fi
-    mv ${OBJ}.tmp ${OBJ}
-    rm -rf ${OBJ}.old
-fi
-
-# TODO download source for above
-# TODO download build dependencies for above
-
-cd ${WORKDIR}
-OBJ=gnomeos-fs
-if ! test -d ${OBJ}; then
-    rm -rf ${OBJ}.tmp
-    cp -al $DEBTARGET-fs ${OBJ}.tmp
-    cd ${OBJ}.tmp/ostree;
-    rm -rf worktree
-    $OSTREE --repo=repo checkout gnomeos worktree
-    cp ${SRCDIR}/debian-setup.sh worktree
-    chroot worktree ./debian-setup.sh
-    rm worktree/debian-setup.sh
-    cd worktree;
-    $OSTREE --repo=../repo commit -b gnomeos -s "Run debian-setup.sh"
-    cd ..
-    rm -rf worktree
-
-    rev=$($OSTREE --repo=repo rev-parse gnomeos);
-    $OSTREE --repo=repo checkout ${rev} gnomeos-${rev}
-    $OSTREE --repo=repo run-triggers gnomeos-${rev}
-    ln -s gnomeos-${rev} current
-    
-    cd ${WORKDIR}
-    if test -d ${OBJ}; then
-        mv ${OBJ} ${OBJ}.old
-    fi
-    mv ${OBJ}.tmp ${OBJ}
-    rm -rf ${OBJ}.old
-fi
-
-cd ${WORKDIR}
-cp ${SRCDIR}/ostree_switch_root ${WORKDIR}
-
-kv=`uname -r`
-kernel=/boot/vmlinuz-${kv}
-if ! test -f "${kernel}"; then
-    cat <<EOF
-Failed to find ${kernel}
-EOF
-fi
-
-cd ${WORKDIR}
-OBJ=gnomeos-initrd.img
-VOBJ=gnomeos-initrd-${kv}.img
-if ! test -f ${OBJ}; then
-    rm -f ${OBJ}.tmp ${VOBJ}.tmp
-    $DRACUT -l -v -o plymouth --include `pwd`/ostree_switch_root /sbin/ostree_switch_root ${VOBJ}.tmp
-    mv ${VOBJ}.tmp ${VOBJ}
-    ln -sf ${VOBJ} gnomeos-initrd.img
-fi